using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class NVfrmTimKiem : Form
    {
        public NVfrmTimKiem()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtDiaChi.Text == "" && txtTen.Text == "" && txtCMND.Text == "")
            {
                MessageBox.Show("Ban phai nhap 1 trong cac o thong tin");
            }
            else
            {
                try
                {
                    DTO.CKHACHHANG kh = new DTO.CKHACHHANG();
                    List<DTO.CPHIEUTHUE> lpt = new List<DTO.CPHIEUTHUE>();

                    if (txtTen.Text != "")
                    {
                        kh = BUS.XuLyKhachHang.TimKhachHangTheoHoTen(txtTen.Text.ToString());

                        lpt = BUS.XuLyPhieuThue.TimPhieuThueTheoMaKH(kh.MaKH);
                    }
                
                    else if (txtDiaChi.Text != "")
                    {
                        kh = BUS.XuLyKhachHang.TimKhachHangTheoDiaChi(txtDiaChi.Text.ToString());

                        lpt = BUS.XuLyPhieuThue.TimPhieuThueTheoMaKH(kh.MaKH);
                    }

                    else if (txtCMND.Text != "")
                    {
                        kh = BUS.XuLyKhachHang.TimKhachHangTheoSoCMND(txtCMND.Text.ToString());

                        lpt = BUS.XuLyPhieuThue.TimPhieuThueTheoMaKH(kh.MaKH);
                    }

                    lblTenKH.Text = kh.HoTen.ToString();
                    lblDiaChi.Text = kh.DiaChi.ToString();
                    lblCMND.Text = kh.CMND.ToString();

                    String Phong = "";
                    foreach (DTO.CPHIEUTHUE pt in lpt)
                    {
                        Phong += " " + pt.MaPhong.ToString();
                        lblNgayThue.Text = pt.BatDauThue.ToShortDateString();
                    }
                    lblPhong.Text = Phong;
                }
                catch (System.Exception )
                {
                	
                }
            }
        }
    }
}